package com.jxc.weather;

import com.imooc.weather.DayWeather;
import com.imooc.weather.HourWeather;
import com.imooc.weather.WeatherUtils;
import com.imooc.weather.impl.WeatherUtilsImpl;

import java.util.List;
import java.util.Scanner;

public class Application {
    public static void main(String[] args) {
        System.out.println("欢迎您体验！以下是开发好的功能：");
        System.out.println("1 查询未来24小时天气预报");
        System.out.println("2 查询未来三天天气预报");
        System.out.println("3 查询未来七天天气预报");
        System.out.print("请输入您要查询的服务前的序号 >>> ");
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        System.out.println("用户选择的输入：" + num);
        if (num == 1){
            System.out.print("请输入要查询的城市名称 >>> ");
            String city_name = scanner.next();
            WeatherUtils weatherUtils = new WeatherUtilsImpl();
            List<HourWeather> weatherList = weatherUtils.w24h("298634ec58c8424eb9cf37405d7b6e39",city_name);
            if (weatherList.size() == 0){
                System.out.println("抱歉，未获取到当前城市的天气信息");
            }else {
                for (HourWeather hourWeather: weatherList){
                    String template = "%s月%s日%s时 %-3s %-20s %-8s %-4s°C";
                   String row = String.format(template,new String[]{
                            hourWeather.getMonth(),
                            hourWeather.getDay(),
                            hourWeather.getHour(),
                            hourWeather.getWindDirection(),
                            hourWeather.getWindPower(),
                            hourWeather.getWeather(),
                            hourWeather.getTemperature()
                    });
                    System.out.println(row);
                }

            }
        }
        if (num == 2){
            System.out.print("请输入要查询的城市名称 >>> ");
            String city_name = scanner.next();
            WeatherUtils weatherUtils = new WeatherUtilsImpl();
            List<DayWeather> weatherList = weatherUtils.w3d("298634ec58c8424eb9cf37405d7b6e39",city_name);
            if (weatherList.size() == 0){
                System.out.println("抱歉，未获取到当前城市的天气信息");
            }else{
                for (DayWeather dayWeather : weatherList){
                    String template = "%-2s月%-2s日 气温：%s°C (日)  %s°C(夜)  天气：%s°C (日)  %s°C(夜) 风力：%-20s (日)  %-20s(夜) ";
                    String row = String.format(template,new String[]{
                            dayWeather.getMonth(),
                            dayWeather.getDay(),
                            dayWeather.getDayAirTemperature(),
                            dayWeather.getNightAirTemperature(),
                            dayWeather.getDayWeather(),
                            dayWeather.getNightWeather(),
                            dayWeather.getDayWindPower(),
                            dayWeather.getNightWindPower()
                    });
                    System.out.println(row);
                }
            }
        }
        if (num == 3){
            System.out.print("请输入要查询的城市名称 >>> ");
            String city_name = scanner.next();
            WeatherUtils weatherUtils = new WeatherUtilsImpl();
            List<DayWeather> weatherList = weatherUtils.w7d("298634ec58c8424eb9cf37405d7b6e39",city_name);
            if (weatherList.size() == 0){
                System.out.println("抱歉，未获取到当前城市的天气信息");
            }else{
                for (DayWeather dayWeather : weatherList){
                    String template = "%-2s月%-2s日 气温：%s°C (日)  %s°C(夜)  天气：%s°C (日)  %s°C(夜) 风力：%-20s (日)  %-20s(夜) ";
                    String row = String.format(template,new String[]{
                            dayWeather.getMonth(),
                            dayWeather.getDay(),
                            dayWeather.getDayAirTemperature(),
                            dayWeather.getNightAirTemperature(),
                            dayWeather.getDayWeather(),
                            dayWeather.getNightWeather(),
                            dayWeather.getDayWindPower(),
                            dayWeather.getNightWindPower()
                    });
                    System.out.println(row);
                }
            }
        }
    }
}
